<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('派单情况-信件')"/>
</head>
<body class="gray-bg">
<div class="container-div">

    <div class="btn-group-sm " id="toolbar" role="group">
        <a class="btn btn-success " onclick="dlSendToSon()">
            <i class="fa"></i> 新增
        </a>
        <a class="btn btn-success single disabled" onclick="recall('')">
            <i class="fa"></i> 撤回
        </a>
    </div>

    <div class="row">
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "system/mMailWF";

    $(function () {
        var options = {
            url: prefix + "/forShow/dealListJson/"+[[${wfId}]],
            detailUrl:  prefix+"/forShow/dealDetail/{id}",
            sortName: "pkId",
            sortOrder: "desc",
            uniqueId: "pkId",
            modalName: "派单情况",
            fixedColumns: true,
            fixedNumber: 1,
            fixedRightNumber: 2,
            columns: [
                {checkbox: true},
                {field:'pkId',title:'用户编号',visible:false},
                {field:'wfId',title:'WfId',visible:false},
                {field:'seqName',title:'交办次序',align:'center'},
                {field:'sortName',title:'办理性质',align:'center'},
                {field:'dealName',title:'办理方式',align:'center',visible:false},
                {field:'sbdeptName',title:'承办单位',align:'center',width:70},
                {field:'sendDesc',title:'办理要求',width:90,align:'center',formatter:function (value, row, index,field) {
                        return "<span style='cursor: pointer;' title='"+value+"'>"+value+"</span>"
                    },
                    cellStyle: cellEllipsis},
                {field:'reason',title:'建议办结及理由',width:90,align:'center'},
                {field:'sdeptName',title:'派发单位',align:'center',width:70},
                {field:'backLimit',title:'要求期限',align:'center',width:80,sortable:true,formatter:function(value,row,index){return interceptDate(value,row,index);}},
                {field:'suserName',title:'派发人',align:'center'},
                {field:'sendTime',title:'派发时间',align:'center',width:80,sortable:true,formatter:function(value,row,index){return interceptDate(value,row,index);}},
                {field:'getTime',title:'签收时间',align:'center',width:80,formatter:function(value,row,index){return interceptDate(value,row,index);}},
                {field:'getPerson',title:'签收人',align:'center'},
                {field:'buserName',title:'回复人',align:'center'},
                {field:'backTime',title:'回复时间',align:'center',width:80,sortable:true,formatter : function(value,row,index){return interceptDate(value,row,index);}},
                {field:'sendState',title:'办理情况',align:'center',formatter:function(value,row,index){return fmtSBSendState(value,row,index);}},
                {
                    title: '查看',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.detail(' + row.pkId + ')"><i class="fa fa-edit"></i>详情</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });


    function recall(){
        $.modal.confirm("确认撤回该条派单记录？",function() {
            var row = $("#bootstrap-table").bootstrapTable('getSelections');
            var sbId = row[0].pkId;
            var deptName = row[0].sdeptName;
            if (deptName == [[${deptName}]]) {
                var url = "/system/mMailWF/cmnFile/returnBack/" + sbId;
                $.ajax({
                    type: "post",
                    url: url,
                    success: function () {
                        parent.$.modal.msgSuccess("撤回成功");
                        $.table.refresh();
                    }
                });
            } else {
                parent.$.modal.msgWarning("非本部门派单无法撤回");
            }
        });
    }

    function dlSendToSon(){
        let pkId = [[${wfId}]];
        let sbId=[[${sbId==null?0:sbId}]];
        var url = ctx + "system/mMailWF/cmnFile/dlSendToSon/"+pkId+"?sbId="+sbId;
        // var url = ctx + "system/mMailWF/cmnFile/dlSendToSon/"+pkId;
        var width = '90%';
        var height = '95%';
        var iframeName = parent.window.name;
        var config = {
            id: 'dlSendToSonDirect',
            title: '拟办部门',
            width: width,
            height: height,
            url: url,
            callBack: function(index, layero) {
                var iframeWin = layero.find('iframe')[0];
                var iframeName = parent.window.name;
                iframeWin.contentWindow.submitHandler(index,iframeName);
            }
        };
        $.modal.openOptions(config);
    }

</script>
</body>
</html>